<?php
ini_set('error_reporting', 6143);
ini_set('display_errors','1');
define('IN_LC', true);
define('MM_ID', 1);

include_once("validate.php");
include_once("includes/style.php");
include_once("includes/news.php");


$done = false;
// are we showing an actual profile?
if(isset($_GET['id']))
{
        $style = new style(false);
	$article = new news(true, $_GET['id'], NEWS_MODE_FULL);
	
	if($article->ok())
	{
		$style->addRenderRight($article);
		$style->render();
		$done = true;
	}
}
else if(isset($_GET['catagory']) && is_numeric($_GET['catagory']))
{
	include_once('includes/renderInclude.php');
	include_once('includes/addMessage.php');
	
	$q = "SELECT *, DATE_FORMAT(n_posteddate, '%W %D %M %Y, %l:%i%p')  as n_posteddateF,
						 (n_stickyexpiry > NOW()) as n_showsticky, COUNT(co_id) as comment_count
		  FROM " . CATAGORIES_TABLE . ", " . NEWSARTICLES_TABLE . " 
		  LEFT JOIN " . COMMENTS_TABLE . " ON n_id = co_catagory_item AND co_catagory = 3 
		  WHERE c_id = n_catagory AND c_newscat = 1 AND n_enabled = 1 AND c_id = " . $_GET['catagory'] . "
		  GROUP BY n_id
		  ORDER BY n_showsticky DESC, n_posteddate DESC
		  LIMIT 0, 10";
		  
	$result = $db->sql_query($q);
	
	$style = new style(true);	
	
	$title = false;
	
	
	while($news_article = $db->sql_fetchrow($result)) 
	{
		if(!$title)
		{
			$title = true;
			$title = '<a href="news.php">' . $lang['NewsListTitle'] . '</a> - <a href="news.php?catagory=' . 
						$news_article['c_id'] . '">' . $news_article['c_title'] . '</a>';
			$style->addRenderRight(new addMessage($lang['NewsListMessage'] . '<br><br>' . catagory_filter($_GET['catagory']), $title));
			$style->addRenderRight(new renderInclude('tpl/tableStart.tpl'));
		}
		
		$article = new news(false, $news_article, NEWS_MODE_MINI);
		if($article->ok())
		{
			$style->addRenderRight($article);
		}
	}
	
	$style->addRenderRight(new renderInclude('tpl/tableEnd.tpl'));
	
	include_once('includes/latest_results.php');
	$style->addRenderLeft(new random_champion());
	$style->addRenderLeft(new random_result());
	$style->addRenderLeft(new random_championship());
	$style->addRenderLeft(new random_event());
	
	$style->render();
	$done = true;
}


if(!$done)
{
	include_once('includes/renderInclude.php');
	include_once('includes/addMessage.php');
	
	$q = "SELECT *, DATE_FORMAT(n_posteddate, '%W %D %M %Y, %l:%i%p')  as n_posteddateF,
						 (n_stickyexpiry > NOW()) as n_showsticky, COUNT(co_id) as comment_count
		  FROM " . CATAGORIES_TABLE . ", " . NEWSARTICLES_TABLE . " 
		  LEFT JOIN " . COMMENTS_TABLE . " ON n_id = co_catagory_item AND co_catagory = 3 
		  WHERE c_id = n_catagory AND c_newscat = 1 AND n_enabled = 1
		  GROUP BY n_id
		  ORDER BY n_showsticky DESC, n_posteddate DESC
		  LIMIT 0, 20";
	$result = $db->sql_query($q);
	
	$style = new style(true);	
	
	$style->addRenderRight(new addMessage($lang['NewsListMessage']. '<br><br>' . catagory_filter(0), '<a href="news.php">' . $lang['NewsListTitle'] . '</a>'));
	$style->addRenderRight(new renderInclude('tpl/tableStart.tpl'));
	
	while($news_article = $db->sql_fetchrow($result)) 
	{
		$article = new news(false, $news_article, NEWS_MODE_MINI);
		if($article->ok())
		{
			$style->addRenderRight($article);
		}
	}
	
	$style->addRenderRight(new renderInclude('tpl/tableEnd.tpl'));
	
	
	
	include_once('includes/latest_results.php');
	$style->addRenderLeft(new random_champion());
	$style->addRenderLeft(new random_result());
	$style->addRenderLeft(new random_championship());
	$style->addRenderLeft(new random_event());
	
	$style->render();
	$done = true;
}


echo $db->num_queries;
?>